package com.updesignsz.api.mapper;

import net.sf.json.JSONObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 项目类型
 * Creation date 2020-8-8 17:53:48
 */
@Repository
@Mapper
public interface TypeMapper {


    @Select({"<script>",
            "SELECT a.id, a.name, COUNT(b.id) AS number FROM `type` a LEFT JOIN `${table}` b ON b.`type` = a.`id` ",
            "<where>",
            "<if test=\"type != null\" >AND a.type = #{type}</if>",
            "<if test=\"name != null\" >AND b.name like '%${name}%'</if>",
            "AND b.is_removed = 0",
            "</where>",
            "group by a.id",
            "order by number desc",
            "</script>"
    })
    List<Map<String, Object>> findByAll(JSONObject json);
}